package com.zsr.example.controller;


import com.alibaba.fastjson.JSONObject;
import com.zsr.example.config.annotation.RequiresPermissions;
import com.zsr.example.service.StatisticsDailyService;
import com.zsr.example.util.CommonUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * <p>
 * 网站统计日数据 前端控制器
 * </p>
 *
 * @author zsr
 * @since 2021-12-22
 */
@RestController
@RequestMapping("/statistics")
public class StatisticsDailyController {
    @Autowired
    private StatisticsDailyService dailyService;

    /**
     * 生成统计
     * @param day
     * @return
     */
    @RequiresPermissions("statistics:add")
    @GetMapping("registerCount/{day}")
    public JSONObject createStatisticsByDate(@PathVariable String day) {
        dailyService.createStatisticsByDay(day,false);
        return CommonUtil.successJson();
    }

    /**
     * 查看图表
     * @param begin
     * @param end
     * @param type
     * @return
     */
    @RequiresPermissions("statistics:chart")
    @GetMapping("showChart/{begin}/{end}/{type}")
    public JSONObject showChart(@PathVariable String begin,@PathVariable String end,@PathVariable String type){
        Map<String, Object> map = dailyService.getChartData(begin, end, type);
        return CommonUtil.successJson(map);
    }

    /**
     * 后台显示统计
     * @return
     */
    @GetMapping("showStatistics")
    public JSONObject showStatistics(){
        Map<String, Object> map = dailyService.showStatistics();
        return CommonUtil.successJson(map);
    }
}

